package com.jwetherell.my.problems.misc;

public class AtoI {

	public static void main(String[] args) {
		String input = "567hello123";
		System.out.println("Input: " + input);
		System.out.println("Output: " + new AtoI().atoi(input));
	}

	int atoi(String inputStr) {
		if (inputStr == null || inputStr.trim().equalsIgnoreCase(""))
			return 0;

		char[] input = inputStr.toCharArray();

		int value = 0;

		for (int i = 0; i < input.length; i++) {
			if (input[i] < '0' || input[i] > '9')
				break;

			value *= 10;
			value += input[i]-'0';
		}

		return value;
	}
}